package com.niubility.server.Impl;

import com.niubility.dao.CheckDepDao;
import com.niubility.entity.Department;
import com.niubility.server.ICheckDepServer;
import com.niubility.server.IColService;
import com.niubility.server.IDepartmentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service("checkDepServer")
@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, readOnly = false)
public class CheckDepServer implements ICheckDepServer{

    @Resource
    private CheckDepDao checkDepDao;
    @Resource
    private IDepartmentService departmentService;
    @Resource
    private IColService collegeService;

    public List<Department> LoadAll(int start,int num){
        return checkDepDao.LoadAll(start,num);
    }

    public boolean Save(Department dep) {
         return checkDepDao.Save(dep)>0?true:false;
    }

    public boolean Delete(int colegeId,String name) {
        //System.out.println("检查表已删除！");
        return checkDepDao.Delete(colegeId,name)>0?true:false;
    }

    public Department select(int colegeId,String name) {
        //System.out.println("查询到数据");
        return checkDepDao.Select(colegeId,name).get(0);
    }
    public int LastInsertID(){
        //System.out.println("获取到社团名称");
        return checkDepDao.LastInsertId();
    }
    public int PageNum(int num){
        int pageNum = checkDepDao.PageNum();
        return pageNum%num == 0?pageNum/num:pageNum/num+1;
    }
}
